﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using Frame.Pages;
using DevExpress.Web.ASPxEditors;


public partial class EditReturnVisit : Frame.Pages.FliterBIEditBasePage<DAL.BLI_ReturnVisit>
{
    protected override Func<DAL.BLI_ReturnVisit, bool> FliterExpression
    {
        get
        {
            if (RefrenceContext<DAL.BI_Consumer>.Current != null)
            {
                return new Func<BLI_ReturnVisit, bool>(o => o.Consumer_ID == RefrenceContext<DAL.BI_Consumer>.Current.Model.ConsumerID);
            }
            else
            {
                return null;
            }
        }
    }

    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        Backlink.NavigateUrl = (RefrenceContext<DAL.BI_Consumer>.Current == null ? string.Empty : RefrenceContext<DAL.BI_Consumer>.Current.BackUrl);
    }

    /// <summary>
    /// 权限编码，需要重新设置
    /// </summary>
    protected override string ActionID
    {
        get { return "0"; }
    }

    protected void gridView_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        e.NewValues["Consumer_ID"] = RefrenceContext<DAL.BI_Consumer>.Current.Model.ConsumerID;
        e.NewValues["Remark"] = getRemark();
    }

    protected void gridView_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
        e.NewValues["Remark"] = getRemark();
    }

    string getRemark()
    {
        string remark = "";
        ASPxDropDownEdit Know = gridView.FindEditFormTemplateControl("ddeKnow") as ASPxDropDownEdit;
        ASPxDropDownEdit Traffic = gridView.FindEditFormTemplateControl("ddeTraffic") as ASPxDropDownEdit;
        ASPxDropDownEdit Change = gridView.FindEditFormTemplateControl("ddeChange") as ASPxDropDownEdit;
        ASPxDropDownEdit Dish = gridView.FindEditFormTemplateControl("ddeDish") as ASPxDropDownEdit;
        ASPxDropDownEdit Server = gridView.FindEditFormTemplateControl("ddeServer") as ASPxDropDownEdit;
        ASPxDropDownEdit Environment = gridView.FindEditFormTemplateControl("ddeEnvironment") as ASPxDropDownEdit;
        ASPxRadioButtonList visit = gridView.FindEditFormTemplateControl("rblvisit") as ASPxRadioButtonList;
        ASPxTextBox other1 = gridView.FindEditFormTemplateControl("txtother1") as ASPxTextBox;
        ASPxTextBox other2 = gridView.FindEditFormTemplateControl("txtother2") as ASPxTextBox;
        ASPxTextBox other3 = gridView.FindEditFormTemplateControl("txtother3") as ASPxTextBox;
        ASPxTextBox other4 = gridView.FindEditFormTemplateControl("txtother4") as ASPxTextBox;
        ASPxTextBox other5 = gridView.FindEditFormTemplateControl("txtother5") as ASPxTextBox;
        ASPxTextBox other6 = gridView.FindEditFormTemplateControl("txtother6") as ASPxTextBox;
        ASPxTextBox Reason = gridView.FindEditFormTemplateControl("txtReason") as ASPxTextBox;

        if (!string.IsNullOrEmpty(Know.Text.Trim()))
        {
            remark += "1.知道途径 \t" + Know.Text.Trim() + "\t\n";
        }
        if (!string.IsNullOrEmpty(other1.Text.Trim()))
        {
            remark += "其他：" + other1.Text.Trim() + "\t\n";
        }
        if (!string.IsNullOrEmpty(Traffic.Text.Trim()))
        {
            remark += "2.交通方式 \t" + Traffic.Text.Trim() + "\t\n";
        }
        if (!string.IsNullOrEmpty(other2.Text.Trim()))
        {
            remark += "其他：" + other2.Text.Trim() + "\t\n";
        }
        if (!string.IsNullOrEmpty(Change.Text.Trim()))
        {
            remark += "3.菜品需要改善 \t" + Change.Text.Trim() + "\t\n";
        }
        if (!string.IsNullOrEmpty(other3.Text.Trim()))
        {
            remark += "其他：" + other3.Text.Trim() + "\t\n";
        }
        if (!string.IsNullOrEmpty(Dish.Text.Trim()))
        {
            remark += "4.不满意菜品 \t" + Dish.Text.Trim() + "\t\n";
        }
        if (!string.IsNullOrEmpty(other4.Text.Trim()))
        {
            remark += "其他：" + other4.Text.Trim() + "\t\n";
        }
        if (!string.IsNullOrEmpty(Server.Text.Trim()))
        {
            remark += "5.不满意服务 \t" + Server.Text.Trim() + "\t\n";
        }
        if (!string.IsNullOrEmpty(other5.Text.Trim()))
        {
            remark += "其他：" + other5.Text.Trim() + "\t\n";
        }
        if (!string.IsNullOrEmpty(Environment.Text.Trim()))
        {
            remark += "6.不满意环境 \t" + Environment.Text.Trim() + "\t\n";
        }
        if (!string.IsNullOrEmpty(other6.Text.Trim()))
        {
            remark += "其他：" + other6.Text.Trim() + "\t\n";
        }
        remark += "7.继续光临% \t" + visit.SelectedItem.Text + "\t\n";
        if (!string.IsNullOrEmpty(Reason.Text.Trim()))
        {
            remark += "原因：" + Reason.Text.Trim() + "\t\n";
        }

        return remark;
    }
}